"""
评论模型类
"""
from typing import Dict, Any
from datetime import datetime


class Comment:
    """
    评论模型类，表示一条评论
    """
    
    def __init__(self, id: str, user_id: str, user_name: str, content: str, 
                 timestamp: str, platform: str, metadata: Dict[str, Any] = None):
        """
        初始化评论对象
        
        @param id: 评论 ID
        @param user_id: 用户 ID
        @param user_name: 用户名
        @param content: 评论内容
        @param timestamp: 时间戳（ISO 格式字符串）
        @param platform: 平台名称
        @param metadata: 元数据，包含额外信息
        """
        self.id = id
        self.user_id = user_id
        self.user_name = user_name
        self.content = content
        self.timestamp = timestamp
        self.platform = platform
        self.metadata = metadata or {}
        
        # 解析时间戳
        try:
            self.datetime = datetime.fromisoformat(timestamp)
        except (ValueError, TypeError):
            self.datetime = datetime.now()
        
        # 分析结果
        self.analysis_result = None
        
        # 回复内容
        self.reply = None
    
    def to_dict(self) -> Dict[str, Any]:
        """
        将评论对象转换为字典
        
        @return: 字典表示
        """
        return {
            "id": self.id,
            "user_id": self.user_id,
            "user_name": self.user_name,
            "content": self.content,
            "timestamp": self.timestamp,
            "platform": self.platform,
            "metadata": self.metadata,
            "analysis_result": self.analysis_result,
            "reply": self.reply
        }
    
    def __str__(self) -> str:
        """
        返回评论的字符串表示
        
        @return: 字符串表示
        """
        return f"{self.user_name}: {self.content}"
    
    def __repr__(self) -> str:
        """
        返回评论的详细字符串表示
        
        @return: 详细字符串表示
        """
        return f"Comment(id='{self.id}', user_name='{self.user_name}', content='{self.content}', timestamp='{self.timestamp}')" 